package edu.student.models;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.util.DB;
/**
Author: Satya Deepthi Bhagi
 **/
public class Interest {

	private String interestName;
	private int interestId;
	
	public String getInterestName() {
		return interestName;
	}

	public void setInterestName(String interestName) {
		this.interestName = interestName;
	}
	
    public int getInterestId() {
		return interestId;
	}
	public void setInterestId(int interestId) {
		this.interestId = interestId;
	}

	public static ArrayList<Interest> getInterests(String selectionModifier) {
		ArrayList<Interest> interests = new ArrayList<Interest>();
		ResultSet resultSet = null;
		String query = "select interest_name from interest i,user u,user_interests ui " + selectionModifier +" and i.interest_id=ui.interest_id and ui.roll_no=u.roll_no";
		Connection connection = DB.getConnection();
		resultSet = DB.readFromDB(query, connection);
		try {
			while (resultSet.next()) {
				Interest interest = new Interest();
				interest.interestName=resultSet.getString("INTEREST_NAME");
				interests.add(interest);	
			}
		} catch (SQLException e) {
	       System.out.println("Exception while reading from db"+ e);
		}
		DB.close(connection);
		return interests;
	}
}
